//function to import javascript class
function debug(obj){
	alert("debug:"+obj);
}
var basePath="js/";
var API_WORKINGREPORT="Hub/WorkingReportAnalyzer";
	

function importJ(fpath){ 

   document.write('<script src="'+ basePath + fpath + '.js" type="text\/javascript"></script>'); 
}

importJ('jquery-ui-1.8.6.custom.min');
importJ('jquery-ui-1.8.6.custom.min');
importJ('jquery.form');
importJ('flexigrid');
importJ('highcharts');

$(document).ready(
		function() {
			loadDataToChart();
		}
);

function loadDataToChart(){
	 $.ajax({
		   type: "GET",
		   url: API_WORKINGREPORT,
		   dataType:'json',
		   success: function(data){
		 		var items=data.items;
		 		if(items.length<2){
		 			$("<div/>").text("数据不符合报表要求").appendTo("#chart_container");
		 			return;
		 		}
		 		rendChart(items)
		 		rendChart2(items[0],0);
		 		rendChart2(items[1],1);
				
		   }
	 });
}
function rendChart2(data,index)
{
	chart = new Highcharts.Chart(
			{
				chart: {
					renderTo: 'chart_container_'+index,
					defaultSeriesType: 'column'
				},
				title: {
					text: data.area+"工作日报分项统计"
				},
				subtitle: {
					text: 'Source: 医疗信息管理系统'
				},
				xAxis: {
					categories: ["阅片","录入","报告发放"]
				},
				yAxis: {
					min: 0,
					title: {
						text: '数量'
					}
				},
				legend: {
					layout: 'vertical',
					backgroundColor: '#FFFFFF',
					align: 'left',
					verticalAlign: 'top',
					x: 100,
					y: 70
				},
				tooltip: {
					formatter: function() {
						return ''+this.x +': '+this.y+'例';
					}
				},
				plotOptions: {
					column: {
						pointPadding: 0.2,
						borderWidth: 0
					}
				},
	           series: [
	                    {
	                    	name: '已',
	                    	data: [data.checkedNumber,data.recordedNumber,data.distributedReportNumber]
	                    }, 
	                    {
	                    	name: '未',
	                    	data: [data.uncheckedNumber,data.unRecordedNumber,data.unDistributedReportNumber] 
	                    }, 
	                   ]
	   });
}
function rendChart(items){
	chart = new Highcharts.Chart(
			{
				chart: {
					renderTo: 'chart_container',
					defaultSeriesType: 'column'
				},
				title: {
					text: "工作日报统计"
				},
				subtitle: {
					text: 'Source: 医疗信息管理系统'
				},
				xAxis: {
					categories: [items[0].area,items[1].area]
				},
				yAxis: {
					min: 0,
					title: {
						text: '数量'
					}
				},
				legend: {
					layout: 'vertical',
					backgroundColor: '#FFFFFF',
					align: 'left',
					verticalAlign: 'top',
					x: 100,
					y: 70
				},
				tooltip: {
					formatter: function() {
						return ''+this.x +': '+this.y+'例';
					}
				},
				plotOptions: {
					column: {
						pointPadding: 0.2,
						borderWidth: 0
					}
				},
	           series: [
	                    {
	                    	name: '收检数量',
	                    	data: [items[0].totalNumber,items[1].totalNumber]
	                    }, 
	                    {
	                    	name: '制片数量',
	                    	data: [items[0].madeNumber,items[1].madeNumber] 
	                    }, 
	                    {
	                    	name: '阳性例数',
	                    	data: [items[0].positiveNumber,items[1].positiveNumber]
	                    }
	                   ]
	   });
}


